package com.wck.car.oyz;

import com.wck.car.model.CarBrandDesc;
import com.wck.car.model.CarSeriesDesc;
import com.wck.car.model.CarParamDesc;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

public class CarParamDescType {

    public static List<CarParamDesc> getCarTypeInfo(CarSeriesDesc carSeriesDesc, CarBrandDesc carBrandDesc){
        String carTypeDescBody = SpiderCar.getBody("https://m.evpartner.com/zyc/param-" + carSeriesDesc.getId() + ".html?seriesid=" + carBrandDesc.getId());
        //System.out.println("!!!!!"+carTypeDescBody);
        Document document = Jsoup.parse(carTypeDescBody);
        Element center = document.getElementsByClass("center").get(0);
        Elements dl = center.getElementsByTag("dl");
        ArrayList<CarParamDesc> carParamDescList = new ArrayList<>();
        dl.forEach(d ->{
            Elements div = dl.get(0).getElementsByTag("div");
            div.forEach(di ->{
                CarParamDesc carParamDesc = new CarParamDesc();
                carParamDesc.setKey(di.getElementsByClass("aname").text());
                carParamDesc.setValue(di.getElementsByClass("avalue").text());
                carParamDesc.setCarSeriesId(carSeriesDesc.getId());
                carParamDescList.add(carParamDesc);
            });
        });
        return carParamDescList;
    }

}
